#include "thread_try.h"


typedef struct thread_args
{
    int thread_num;
    char * thread_name;
} thread_args;


void * son_thread_funcion(void * args){
    thread_args * thd_args = (thread_args *) args;
    printf("==================%s开始==================\n", thd_args->thread_name);
    printf("子线程开始睡眠\n");
    for (int i=0; i<5; i++){
        sleep(1);
        printf("%ds\n", i);
    }
    printf("子线程睡眠结束\n");
    printf("==================%s结束==================\n", thd_args->thread_name);
    return 0;
}


int main(int argc, char * argv[]){

    thread_args * args = (thread_args *) malloc(sizeof(args));
    if (args == NULL){
        printf("创建线程参数失败，退出...\n");
        return -1;
    }
    args->thread_name = "thread 1";
    args->thread_num = 1;

    printf("==================主线程开始==================\n");
    printf("开始创建子线程\n");

    pthread_t t_id;
    int create_flag = pthread_create(&t_id, NULL, (void *)son_thread_funcion, (void *)args);
    printf("主线程睡眠3秒\n");
    sleep(3);
    printf("主线程结束睡眠\n");
    printf("==================主线程结束==================\n");
    printf("主线程结束运行, 子函数结束运行\n");
    return 0;
}